package com.sxt.service.impl;

import java.util.Scanner;

import com.sxt.exception.InputException;
import com.sxt.util.InputTools;

/**
 * 输入规范性检查
 * @author lovemanai
 *
 */
public class InputCheck {
	
	static Scanner input = new Scanner(System.in);
	
	/*
	 * 检查密码输入
	 */
	public static void passwordCheck(String password) throws InputException {
		if(!password.matches("\\d{6}")) {
			throw new InputException();
		}
		
	}
	
	/*
	 * 检查输入的钱款
	 */
	public static void moneyCheck(double money) throws InputException {
		if(money % 100 != 0 || money % 50 != 0) {
			throw new InputException();
		}
		
	}
	
	/*
	 * 密码检查
	 */
	public static String checkPassword() {
		boolean flag = true;
		String password = InputTools.getString("请输入密码:", input);
		while(flag) {
			try {
				InputCheck.passwordCheck(password);
				flag = false;
			} catch (InputException e) {
				e.printErrorMsg("密码格式不符合规范，请重新输入！");
				password = InputTools.getString("请输入密码:", input);
			}
		}
		return password;
	}
	
	/*
	 * 钱款检查
	 */
	public static double checkMoney() {
		boolean flag = true;
		double money = InputTools.getDouble("请输入钱款:", input);
		while(flag) {
			try {
				InputCheck.moneyCheck(money);
				flag = false;
			} catch (InputException e) {
				e.printErrorMsg("存入钱款格式不符合规范，请重新输入！");
				money = InputTools.getDouble("请输入钱款:", input);;
			}
		}
		
		return money;
	}
} 
